package cn.cloudgateway9527.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Gateway路由配置类
 * 配置自定义路由规则
 */
@Configuration
public class GatewayConfig {

    /**
     * 自定义路由配置
     * 这里可以添加更复杂的路由规则
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                // 用户服务路由 - 支持负载均衡
                .route("heritage-service-route", r -> r
                        .path("/api/heritages/**")
                        .uri("lb://cloud-heritage-service")
                )
                // Feign客户端路由 - 统一入口
                .route("feign-client-route", r -> r
                        .path("/feign/**")
                        .uri("lb://cloud-heritage-feign")
                )
                // 负载均衡信息路由
                .route("loadbalancer-info-route", r -> r
                        .path("/loadbalancer/**")
                        .uri("lb://cloud-heritage-feign")
                )
                .build();
    }
}
